home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 1FQB1FQ (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  8.1 KB  |  225 lines

  1. package com.sun.java.swing.text;
  2.  
  3. import java.io.IOException;
  4. import java.io.ObjectInputStream;
  5. import java.io.ObjectOutputStream;
  6. import java.io.PrintStream;
  7. import java.io.Serializable;
  8. import java.util.Enumeration;
  9.  
  10. public abstract class AbstractDocument$AbstractElement implements Element, MutableAttributeSet, Serializable {
  11.    // $FF: synthetic field
  12.    AbstractDocument this$0;
  13.    private Element parent;
  14.    private transient AttributeSet attributes;
  15.  
  16.    // $FF: synthetic method
  17.    public AbstractDocument$AbstractElement(AbstractDocument this$0, Element parent, AttributeSet a) {
  18.       this.this$0 = this$0;
  19.       this.attributes = a != null ? a.copyAttributes() : this$0.getAttributeContext().getEmptySet();
  20.       this.parent = parent;
  21.    }
  22.  
  23.    private final void indent(PrintStream out, int n) {
  24.       for(int i = 0; i < n; ++i) {
  25.          out.print("  ");
  26.       }
  27.  
  28.    }
  29.  
  30.    public void dump(PrintStream out, int indentAmount) {
  31.       this.indent(out, indentAmount);
  32.       if (this.getName() == null) {
  33.          out.print("<??");
  34.       } else {
  35.          out.print("<" + this.getName());
  36.       }
  37.  
  38.       if (this.getAttributeCount() > 0) {
  39.          out.println("");
  40.          Enumeration names = this.attributes.getAttributeNames();
  41.  
  42.          while(names.hasMoreElements()) {
  43.             Object name = names.nextElement();
  44.             this.indent(out, indentAmount + 1);
  45.             out.println(name + "=" + this.getAttribute(name));
  46.          }
  47.  
  48.          this.indent(out, indentAmount);
  49.       }
  50.  
  51.       out.println(">");
  52.       if (this.isLeaf()) {
  53.          this.indent(out, indentAmount + 1);
  54.          out.print("[" + this.getStartOffset() + "," + this.getEndOffset() + "]");
  55.          AbstractDocument.Content c = this.this$0.getContent();
  56.  
  57.          try {
  58.             String contentStr = c.getString(this.getStartOffset(), this.getEndOffset() - this.getStartOffset()).trim();
  59.             if (contentStr.length() > 40) {
  60.                contentStr = contentStr.substring(0, 40) + "...";
  61.             }
  62.  
  63.             out.println(contentStr);
  64.          } catch (BadLocationException var6) {
  65.          }
  66.       } else {
  67.          int n = this.getElementCount();
  68.  
  69.          for(int i = 0; i < n; ++i) {
  70.             AbstractDocument$AbstractElement e = (AbstractDocument$AbstractElement)this.getElement(i);
  71.             e.dump(out, indentAmount + 1);
  72.          }
  73.       }
  74.  
  75.    }
  76.  
  77.    protected void finalize() throws Throwable {
  78.       AbstractDocument.AttributeContext context = this.this$0.getAttributeContext();
  79.       context.reclaim(this.attributes);
  80.    }
  81.  
  82.    public int getAttributeCount() {
  83.       return this.attributes.getAttributeCount();
  84.    }
  85.  
  86.    public boolean isDefined(Object attrName) {
  87.       return this.attributes.isDefined(attrName);
  88.    }
  89.  
  90.    public boolean isEqual(AttributeSet attr) {
  91.       return this.attributes.isEqual(attr);
  92.    }
  93.  
  94.    public AttributeSet copyAttributes() {
  95.       return this.attributes;
  96.    }
  97.  
  98.    public Object getAttribute(Object attrName) {
  99.       Object value = this.attributes.getAttribute(attrName);
  100.       if (value == null) {
  101.          AttributeSet a = this.parent != null ? this.parent.getAttributes() : null;
  102.          if (a != null) {
  103.             value = a.getAttribute(attrName);
  104.          }
  105.       }
  106.  
  107.       return value;
  108.    }
  109.  
  110.    public Enumeration getAttributeNames() {
  111.       return this.attributes.getAttributeNames();
  112.    }
  113.  
  114.    public boolean containsAttribute(Object name, Object value) {
  115.       return this.attributes.containsAttribute(name, value);
  116.    }
  117.  
  118.    public boolean containsAttributes(AttributeSet attrs) {
  119.       return this.attributes.containsAttributes(attrs);
  120.    }
  121.  
  122.    public AttributeSet getResolveParent() {
  123.       AttributeSet a = this.attributes.getResolveParent();
  124.       if (a == null && this.parent != null) {
  125.          a = this.parent.getAttributes();
  126.       }
  127.  
  128.       return a;
  129.    }
  130.  
  131.    public void addAttribute(Object name, Object value) {
  132.       this.checkForIllegalCast();
  133.       AbstractDocument.AttributeContext context = this.this$0.getAttributeContext();
  134.       this.attributes = context.addAttribute(this.attributes, name, value);
  135.    }
  136.  
  137.    public void addAttributes(AttributeSet attr) {
  138.       this.checkForIllegalCast();
  139.       AbstractDocument.AttributeContext context = this.this$0.getAttributeContext();
  140.       this.attributes = context.addAttributes(this.attributes, attr);
  141.    }
  142.  
  143.    public void removeAttribute(Object name) {
  144.       this.checkForIllegalCast();
  145.       AbstractDocument.AttributeContext context = this.this$0.getAttributeContext();
  146.       this.attributes = context.removeAttribute(this.attributes, name);
  147.    }
  148.  
  149.    public void removeAttributes(Enumeration names) {
  150.       this.checkForIllegalCast();
  151.       AbstractDocument.AttributeContext context = this.this$0.getAttributeContext();
  152.       this.attributes = context.removeAttributes(this.attributes, names);
  153.    }
  154.  
  155.    public void removeAttributes(AttributeSet attrs) {
  156.       this.checkForIllegalCast();
  157.       AbstractDocument.AttributeContext context = this.this$0.getAttributeContext();
  158.       if (attrs == this) {
  159.          this.attributes = context.getEmptySet();
  160.       } else {
  161.          this.attributes = context.removeAttributes(this.attributes, attrs);
  162.       }
  163.  
  164.    }
  165.  
  166.    public void setResolveParent(AttributeSet parent) {
  167.       this.checkForIllegalCast();
  168.       AbstractDocument.AttributeContext context = this.this$0.getAttributeContext();
  169.       if (parent != null) {
  170.          this.attributes = context.addAttribute(this.attributes, StyleConstants.ResolveAttribute, parent);
  171.       } else {
  172.          this.attributes = context.removeAttribute(this.attributes, StyleConstants.ResolveAttribute);
  173.       }
  174.  
  175.    }
  176.  
  177.    private final void checkForIllegalCast() {
  178.       Thread t = this.this$0.getCurrentWriter();
  179.       if (t == null || t != Thread.currentThread()) {
  180.          throw new StateInvariantError("Illegal cast to MutableAttributeSet");
  181.       }
  182.    }
  183.  
  184.    public Document getDocument() {
  185.       return this.this$0;
  186.    }
  187.  
  188.    public Element getParentElement() {
  189.       return this.parent;
  190.    }
  191.  
  192.    public AttributeSet getAttributes() {
  193.       return this;
  194.    }
  195.  
  196.    public String getName() {
  197.       return this.attributes.isDefined("$ename") ? (String)this.attributes.getAttribute("$ename") : null;
  198.    }
  199.  
  200.    public abstract int getStartOffset();
  201.  
  202.    public abstract int getEndOffset();
  203.  
  204.    public abstract Element getElement(int var1);
  205.  
  206.    public abstract int getElementCount();
  207.  
  208.    public abstract int getElementIndex(int var1);
  209.  
  210.    public abstract boolean isLeaf();
  211.  
  212.    private void writeObject(ObjectOutputStream s) throws IOException {
  213.       s.defaultWriteObject();
  214.       StyleContext.writeAttributeSet(s, this.attributes);
  215.    }
  216.  
  217.    private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
  218.       s.defaultReadObject();
  219.       MutableAttributeSet attr = new SimpleAttributeSet();
  220.       StyleContext.readAttributeSet(s, attr);
  221.       AbstractDocument.AttributeContext context = this.this$0.getAttributeContext();
  222.       this.attributes = context.addAttributes(SimpleAttributeSet.EMPTY, attr);
  223.    }
  224. }
  225.